package gov.nhso.prov.acc.utils;

public class BathText{

	
	public String bathText(String bath)
	{
		
		Double bathValue = 0.00;
		Double satangValue = 0.00;
		
		String bathTxtValue = "0"; 
		String satangTxtValue = "0";
		
		if(bath.indexOf(".") >= 0)//have satang
		{
			bathTxtValue = bath.substring(0, bath.indexOf("."));
			
			if(bathTxtValue.length() == 0)
				bathTxtValue = "0";
			
			satangTxtValue = bath.substring(bath.indexOf(".") + 1);
		}		
		else
		{
			bathTxtValue = bath;
		}
		
		bathValue = Double.parseDouble(bathTxtValue.replaceAll(",", ""));
		satangValue = Double.parseDouble(satangTxtValue.replaceAll(",", ""));
		
		return bathText(bathValue, satangValue);
	}
	
	public String bathText(Double bath, Double satang)
	{
		String result = "";
		
		if(satang > 0)
		{			
			result = _bathText(satang, 0) + "\u0e2a\u0e15\u0e32\u0e07\u0e04\u0e4c";
		}
		
		String bathTextValue = _bathText(bath, 0);
		
		if(bathTextValue.length() > 0)
			if(satang > 0)
			{
				result = _bathText(bath, 0) + "\u0e1a\u0e32\u0e17" + result;
			}else{
				result = _bathText(bath, 0) + "\u0e1a\u0e32\u0e17" + result + "\u0e16\u0e49\u0e27\u0e19";	
			}
		else
			result = result + "\u0e16\u0e49\u0e27\u0e19";
				
		return result;		
	}
	
	public String _bathText(Double bath, int position)
	{
		String[] numbericText = {"", "\u0e2b\u0e19\u0e36\u0e48\u0e07", "\u0e2a\u0e2d\u0e07", "\u0e2a\u0e32\u0e21", "\u0e2a\u0e35\u0e48", "\u0e2b\u0e49\u0e32", "\u0e2b\u0e01", "\u0e40\u0e08\u0e47\u0e14",  "\u0e41\u0e1b\u0e14", "\u0e40\u0e01\u0e49\u0e32",  "\u0e40\u0e2d\u0e47\u0e14", "\u0e22\u0e35\u0e48"}; 
	
		String[] postionText = {"", "\u0e2a\u0e34\u0e1a", "\u0e23\u0e49\u0e2d\u0e22", "\u0e1e\u0e31\u0e19", "\u0e2b\u0e21\u0e37\u0e48\u0e19", "\u0e41\u0e2a\u0e19", "\u0e25\u0e49\u0e32\u0e19"};
		
		String result = "";
		boolean flagMillion = false;
		if(position == 6 && bath / 10 > 0){		
			flagMillion = true;
			position = 0;
		}else if(position > 6)
			position = 0;
		
		if(bath >= 1 && (bath % 10 != 0 || bath / 10 > 0))
		{
			int index = (int)(bath % 10);
			
			result = _bathText(bath / 10, position + 1);

			if(position == 0 && index == 1 && bath / 10 >= 1)
				result = result + numbericText[10];
			else if(position == 1 && index == 2)
				result = result + numbericText[11];
			else if(position != 1 || index != 1)
				result = result + numbericText[index];					
			
			if (flagMillion)
				result = result + postionText[6];
			else if(index != 0)
				result = result + postionText[position];
		}
		
		return result;		
	}
}
